
Imports QuickGraph

Namespace Aricie.DNN.Caching.Analysis.Graphs
    Public Class ClusteringGraphFilter

        Private _settings As AutoConfigSettings
        Private _originalGraph As BidirectionalGraph(Of DistributedCachingNode, DistributedCachingEdge)

        Public Sub New(ByVal settings As AutoConfigSettings, ByVal originalGraph As BidirectionalGraph(Of DistributedCachingNode, DistributedCachingEdge))
            Me._settings = settings
            Me._originalGraph = originalGraph
        End Sub

        Public Function VertexPredicate(ByVal v As DistributedCachingNode) As Boolean
            'Select Case v.NodeType
            '    Case TargetNodeType.TargetJob
            '        Return False
            '    Case TargetNodeType.KeyStat
            '        Return True
            'End Select
            Return True
        End Function

        Public Function EdgePredicate(ByVal e As DistributedCachingEdge) As Boolean
            If e.Tag.Frequency > Me._settings.MinPercentageNextKeyForGroup Then
                Dim inEdges As IEnumerable(Of DistributedCachingEdge) = Nothing
                If Me._originalGraph.TryGetInEdges(e.Target, inEdges) Then
                    Dim totalCount As Integer
                    For Each objEdge As DistributedCachingEdge In inEdges
                        totalCount += objEdge.Tag.Count
                    Next
                    If Convert.ToInt32(e.Tag.Count * 100 / totalCount) > Me._settings.MinPercentagePrevKeyForGroup Then
                        Return True
                    End If
                End If
            End If
            Return False
        End Function


    End Class
End Namespace